/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.uuid.UUIDGenerator;
import cn.qidisoft.edu.hzjt.dao.TwglStudentCorpActivityMapper;
import cn.qidisoft.edu.hzjt.model.TwglStudentCorpActivity;
import cn.qidisoft.edu.hzjt.service.ITwglStudentCorpActivityService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: BjxxClassMaterialProjectServiceImpl.java, v 0.1 2018年10月29日 下午1:14:36 hhl Exp $
 */
@Service("twglStudentCorpActivityService")
public class TwglStudentCorpActivityServiceImpl implements ITwglStudentCorpActivityService {

    protected static final LoggerAdapter  LOGGER = LoggerAdapterFactory
        .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    private TwglStudentCorpActivityMapper twglStudentCorpActivityMapper;

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryList(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public List<TwglStudentCorpActivity> queryList(TwglStudentCorpActivity data) {
        try {
            return twglStudentCorpActivityMapper.queryList(data);

        } catch (Exception e) {
            LOGGER.error("queryList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryByPK(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public TwglStudentCorpActivity queryByPK(TwglStudentCorpActivity data) {
        try {
            return twglStudentCorpActivityMapper.queryByPK(data);
        } catch (Exception e) {
            LOGGER.error("queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#add(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public String add(TwglStudentCorpActivity data) {
        String uuid = UUIDGenerator.genReqID();
        try {
            data.setGid(uuid);
            twglStudentCorpActivityMapper.add(data);
        } catch (Exception e) {
            LOGGER.error("add [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
        return uuid;
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#update(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void update(TwglStudentCorpActivity data) {
        try {
            twglStudentCorpActivityMapper.update(data);
        } catch (Exception e) {
            LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#delete(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void delete(TwglStudentCorpActivity data) {
        try {
            twglStudentCorpActivityMapper.delete(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryPageList(cn.qidisoft.microClass.resource.model.basis.Catalog, cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<TwglStudentCorpActivity> queryPageList(TwglStudentCorpActivity data,
                                                                 Page page) {
        try {

            int c = twglStudentCorpActivityMapper.queryPageListcount(data);
            int totalRecords = 0;
            totalRecords = (int) c;
            PaginationBean<TwglStudentCorpActivity> pageHolder = new PaginationBean<TwglStudentCorpActivity>(
                page, totalRecords);
            List<TwglStudentCorpActivity> resultList = twglStudentCorpActivityMapper.queryPageList(
                data, new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#validation(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public int validation(TwglStudentCorpActivity data) {
        try {
            return twglStudentCorpActivityMapper.validation(data);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.ITwglStudentCorpActivityService#queryPageList_admin(cn.qidisoft.edu.hzjt.model.TwglStudentCorpActivity, cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<TwglStudentCorpActivity> queryPageList_admin(TwglStudentCorpActivity data,
                                                                       Page page) {
        try {

            int c = twglStudentCorpActivityMapper.queryPageListcount_admin(data);
            int totalRecords = 0;
            totalRecords = (int) c;
            PaginationBean<TwglStudentCorpActivity> pageHolder = new PaginationBean<TwglStudentCorpActivity>(
                page, totalRecords);
            List<TwglStudentCorpActivity> resultList = twglStudentCorpActivityMapper
                .queryPageList_admin(data,
                    new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                        pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.ITwglStudentCorpActivityService#auditList(cn.qidisoft.edu.hzjt.model.TwglStudentCorpActivity)
     */
    @Override
    @Transactional
    public void auditList(TwglStudentCorpActivity data) {
        try {
            for (String s : data.getIds()) {
                /*    TwglStudentCorpActivity data1 = new TwglStudentCorpActivity();*/
                data.setHdid(Integer.valueOf(s));
                /*  data1.setStates(data.getStates());
                data1.setAudittime(data.getAudittime());
                data1.setAuditorid(data.getAuditorid());
                data1.setAuditsuggestion(null);*/
                twglStudentCorpActivityMapper.auditList(data);
            }
        } catch (Exception e) {
            LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.edu.hzjt.service.ITwglStudentCorpActivityService#export(cn.qidisoft.edu.hzjt.model.TwglStudentCorpActivity)
     */
    @Override
    public List<TwglStudentCorpActivity> export(TwglStudentCorpActivity data) {
        try {
            return twglStudentCorpActivityMapper.export(data);
        } catch (Exception e) {
            LOGGER.error("export [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

}
